import { api } from "../api"

export function fetchResourceApi(courseFileId: string | null, sentence: string) {
  try {
    return api.get('/java/teacher/StudySpaceTeacher/sorted-resources', {
      params: {
        courseFileId,
        sentence,
      },
    });
  }
  catch (error) {
    throw new Error('获取章节资源失败')
  }
}
export function handleResourceDropApi(payload: any) {
  try {
    return api.post('/java/teacher/StudySpaceTeacher/updateSortOrder', payload);
  }
  catch (error) {
    throw new Error('排序失败')
  }
}

export function deleteResourceApi(source_id: string | null, type: string) {
  try {
    return api.get('/java/teacher/StudySpaceTeacher/deleteSources', {
      params: {
        source_id,
        type,
      },
    });
  }
  catch (error) {
    throw new Error('排序失败')
  }
}
export function RenameResourceApi(courseFileId: string, newFileName: string, type: string) {
  try {
    return api.post('/java/teacher/StudySpaceTeacher/updateCourseFileName', null, {
      params: {
        courseFileId,
        newFileName,
        type,
      },
    });
  }
  catch (error) {
    throw new Error('课程重命名失败');
  }
}
export function MoveResourceApi(resourceId: string | null, resourceType: string | null, newPath: string, courseId: string | null) {
  try {
    return api.post('/java/teacher/StudySpaceTeacher/moveResourse', null, {
      params: {
        resourceId,
        resourceType,
        newPath,
        courseId,
      },
    });
  }
  catch (error) {
    throw new Error('课程重命名失败');
  }
}
export function fetchUrlApi(sourceId: string | null) {
  try {
    return api.get('/java/ground/study/course/get_source_url', {
      params: {
        sourceId,
      },
    });
  }
  catch (error) {
    throw new Error('获取链接失败');
  }
}
export function fetchKnowledgeSpaceApi() {
  try {
    return api.get('/java/teacher/StudySpaceTeacher/has_knowledge_space');
  }
  catch (error) {
    throw new Error('获取知识空间错误');
  }
}

export function fetchFlowStatus() {
  try {
    return api.get('/java/teacher/handlefileSource/status');
  }
  catch (error) {
    throw new Error('获取知识空间错误');
  }
}
